{% extends "data_opform.html" %}
{% load i18n %}

{% block form %}
{% autoescape off %}
	<tr><td>
	<div id="show_emp_tree" style="width:670px;display:block;"></div>
	</td><td></td>
	    </tr>
		<tr>
            <td height="20">{{ form.department|field_as_label_tag }}   <span>{{form.department.as_widget }}</span></td>
            <td></td>
         </tr>
      	<tr>
	        <td>
	        	<label for="id_parent" class="required">{%trans '选择职位' %}</label>
	        <input id="id_show_input" class="wZBaseCharField input_showDeptTree required position_tree" type="text" readonly="readonly" value=""></input>
			<span class="t_btn_showDeptTree">
			    <img id="id_drop_dept" onclick="javascript:$(this).parent().find('#show_deptment').show().bgiframe();" src="/media/img/sug_down_on.gif"></img>
			    <div id="show_deptment" style="display: none;">
			        <div class="title" >
			            <span class="close btn" onclick="javascript:$(this).parent().parent().parent().find('#show_deptment').hide();">
			                {% trans '确定' %}
			            </span>
			        </div>
			        <div id="id_dept" class="dispayN">
			            <ul id="position_tree_by_dept" class="tree"></ul>
			        </div>
			    </div>
			<input type="hidden" id="flag">
			</span>
			</td>
			<td></td>
     	</tr>
	<input type="hidden" id="filter_emp_empwidget">
{% endautoescape %}
{% endblock %}

{% block addjs %}
before_submit =function(){
	
    var v = $("#id_dept_all").attr("checked");
    if (v){
        var iItems = $("div[id^='emp_select_']").get(0).g.data.length
        if (v && iItems<=0){
            $('#id_info').html("<ul class='errorlist'><li>"+gettext('请选择人员!')+"</li></ul>")
            return false
        }
    }else{
    	var c= $("input[type='checkbox'][name='UserIDs']")
      	if (c.length<=0){
	          $('#id_info').html("<ul class='errorlist'><li>"+gettext('请选择人员!')+"</li></ul>")
	          return false
      	}
    }
    if(typeof $("input[name='department']").val() == 'undefined' || $("input[name='department']").val().trim().length==0 ){
		$('#id_info').html("<ul class='errorlist'><li>"+gettext('请选择部门!')+"</li></ul>")
		return false
	}
	if($(".position_tree").val().trim().length==0){
		$('#id_info').html("<ul class='errorlist'><li>"+gettext('请选择职位!')+"</li></ul>")
		return false
	}else {
	
          $('#id_info').html("")
          return true
    } 
}

$(function(){
	$("tr#pre_addition_fields").css({display:"none"});
    $.ajax({
        url:"/iclock/choice_widget_for_select_emp/?multiple=T&name=UserIDs&filter_emp=T",
        type:"POST",
        dataType:"html",
        success:function(sdata){            
            $("#show_emp_tree").html(sdata);
        }
    });
})


{% endblock%}
